import { ComponentListItem, ComponentType } from './types'
import { v4 as uuidv4 } from 'uuid'

/**
 * 根据组件类型返回对应的默认标签
 * @param {ComponentType} type - 组件类型
 */
export const useGetComponentDefaultLabelByType = (type: ComponentType) => {
  const ComponentTypeDefaultLabelMap: Record<ComponentType, string> = {
    input: '单行输入',
    radio: '单选框',
    textarea: '多行文本',
    checkbox: '多选框',
    'single-select': '下拉单选',
    'multiple-select': '下拉多选',
    'date-time': '日期时间',
    'file-upload': '文件上传',
    address: '地址选择',
    'data-connect': '关联数据',
    'child-form': '表格',
    divider: '',
  }

  return ComponentTypeDefaultLabelMap[type]
}

/**
 * 获取默认的组件对象
 * @param type - 组件类型
 * @param beAssociated - 是否被关联
 * @param label - 组件默认的标签名
 */
export const useGetDefaultComponetRow = (
  type: ComponentType,
  beAssociated = false,
  label?: string,
): ComponentListItem => {
  return {
    type,
    width: '1/4',
    label: label || useGetComponentDefaultLabelByType(type),
    id: uuidv4(),
    isDrag: false,
    required: false,
    inputConfig: {
      maxLength: 200,
      mode: 1,
      numberMax: 999999999,
      amountMax: 999999999.99,
      placeholder: '请输入内容',
    },
    textareaConfig: {
      maxLength: 200,
      placeholder: '请输入内容',
    },
    radioConfig: {
      options: [
        { label: '选项1', value: 1 },
        { label: '选项2', value: 2 },
        { label: '选项3', value: 3 },
      ],
    },
    checkboxConfig: {
      options: ['选项1', '选项2', '选项3'],
    },
    singleSelectConfig: {
      options: [
        { label: '选项1', value: uuidv4() },
        { label: '选项2', value: uuidv4() },
        { label: '选项3', value: uuidv4() },
      ],
      placeholder: '请选择',
      beControlVisibleRules: [],
    },
    multipleSelectConfig: {
      options: [
        { label: '选项1', value: 1 },
        { label: '选项2', value: 2 },
        { label: '选项3', value: 3 },
      ],
      placeholder: '请选择',
    },
    dividerConfig: {
      title: '标题',
      titleColor: '#007cff',
      dividerColor: '#007cff',
      style: 'style3',
    },
    dateTimeConfig: {
      dateTimeType: 'date',
      placeholder: '请选择日期时间',
    },
    fileUploadConfig: {
      num: 5,
      size: 50,
      type: 'picture',
    },
    dataConnectConfig: {
      type: '',
      fieldList: [],
      showFormFieldList: [],
      fillRules: [],
      selectMode: 1,
    },
    childFormConfig: [],
    delPopoverVisible: false,
    beAssociated,
    beControlVisible: false,
  }
}
